package com.ncs.base.common.rule;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.FileHeader;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import com.ncs.base.task.config.RemindJob;
import com.ncs.base.task.entity.AddRequest;
import com.ncs.base.task.entity.TaskEntity;
import com.ncs.base.task.entity.TimeTaskEntity;
import com.ncs.base.task.service.UserMasterService;


/**
 * @Auther: ZLF
 * @Date: 2018/6/28 10:03
 * @Description:zip文件解压缩工具类
 */
public class JobUtils {

	  /**
	 * @param <T>
     */
    public static <T> String setJobSchedulerFactory(Class c,SchedulerFactoryBean schedulerFactoryBean,AddRequest request, TaskEntity task) throws Exception{
    	
    	TimeTaskEntity timedTask = new TimeTaskEntity();
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        try {
			Set<JobKey> jobKeySet = scheduler.getJobKeys(GroupMatcher.anyGroup());
		} catch (SchedulerException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(DateUtil.timeToCron(request.getOneTime()));
        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("oneTime2" + task.getId(), "remind")
                .withSchedule(cronScheduleBuilder)
                .usingJobData("taskId", task.getId())
                .usingJobData("taskName", task.getName())
                .usingJobData("tableName", task.getTableName())
                .usingJobData("execution", request.getOneTime())
                .build();

        JobDetail jobDetail = JobBuilder.newJob(c)
                .usingJobData("taskId2", task.getId())
                .usingJobData("taskName", task.getName())
                .usingJobData("execution", request.getOneTime())
                .usingJobData("tableName", task.getTableName())
                .withIdentity("oneTime" + task.getId(), "remind")
                .storeDurably()
                .build();
      //4、执行
			scheduler.scheduleJob(jobDetail, trigger);
			scheduler.start();
		return null;

    }
    
    
    
}
